#include "pilotView.h"
#include "camera/first_person_camera.h"

PilotView::PilotView(const Rectangle& viewport,SceneModel& model)
	:	SceneView(viewport,model),
		subView(Rectangle(0,300,0,300),model){
	Helicopter& helicopter = model.getHelicopter();
	Point center = helicopter.getDimensions().center();

	float fovUp  = 60.0;
	float aspect = ((GLfloat) viewport.width()/(GLfloat) viewport.height());
	float zNear  = 0.10f;
	float zFar   = 1500.0f;
	camera= new FirstPersonCamera(	center+Point(0,1,0),center,Point(0,0,1),
									fovUp,aspect,zNear,zFar);
}

PilotView::~PilotView(){

}

void PilotView::setEnv(){
	glViewport ((GLint) viewport.x1,(GLint) viewport.y1, (GLsizei) viewport.width(), (GLsizei) viewport.height());
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}

void PilotView::applyWorldTransformations(){
	/*Point iangle = model.getHelicopter().getInclinationAngle();
	Point center = model.getHelicopter().getDimensions().center();
	glTranslatef(center.x1,center.x2,center.x3);
	glRotatef(model.getHelicopter().getZRotatedAngle()*180/PI,0,0,1);

	glRotatef(-iangle.x1*180/PI,0,1,0);
	glRotatef(iangle.x2*180/PI,1,0,0);


	glRotatef(-model.getHelicopter().getZRotatedAngle()*180/PI,0,0,1);
	glTranslated(-center.x1,-center.x2,-center.x3);*/
}

Camera& PilotView::getSubViewCamera(){
	return subView.getCamera();
}

void PilotView::display(){
	SceneView::display();

	subView.display();
}
